package de.hwrberlin.remo.diagram.part;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.eclipse.gef.Tool;
import org.eclipse.gef.palette.PaletteContainer;
import org.eclipse.gef.palette.PaletteDrawer;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.palette.ToolEntry;
import org.eclipse.gmf.runtime.diagram.ui.tools.UnspecifiedTypeConnectionTool;
import org.eclipse.gmf.runtime.diagram.ui.tools.UnspecifiedTypeCreationTool;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;

import de.hwrberlin.remo.diagram.providers.RemoElementTypes;

/**
 * @generated
 */
public class RemoPaletteFactory {

	/**
	 * @generated
	 */
	public void fillPalette(PaletteRoot paletteRoot) {
		paletteRoot.add(createFacts1Group());
		paletteRoot.add(createRules2Group());
		paletteRoot.add(createConnections3Group());
	}

	/**
	 * Creates "Facts" palette tool group
	 * @generated
	 */
	private PaletteContainer createFacts1Group() {
		PaletteDrawer paletteContainer = new PaletteDrawer(
				Messages.Facts1Group_title);
		paletteContainer.setId("createFacts1Group"); //$NON-NLS-1$
		paletteContainer.setDescription(Messages.Facts1Group_desc);
		paletteContainer.add(createFact1CreationTool());
		return paletteContainer;
	}

	/**
	 * Creates "Rules" palette tool group
	 * @generated
	 */
	private PaletteContainer createRules2Group() {
		PaletteDrawer paletteContainer = new PaletteDrawer(
				Messages.Rules2Group_title);
		paletteContainer.setId("createRules2Group"); //$NON-NLS-1$
		paletteContainer.add(createIMPLICATION1CreationTool());
		paletteContainer.add(createAND2CreationTool());
		paletteContainer.add(createOR3CreationTool());
		return paletteContainer;
	}

	/**
	 * Creates "Connections" palette tool group
	 * @generated
	 */
	private PaletteContainer createConnections3Group() {
		PaletteDrawer paletteContainer = new PaletteDrawer(
				Messages.Connections3Group_title);
		paletteContainer.setId("createConnections3Group"); //$NON-NLS-1$
		paletteContainer.add(createPremise1CreationTool());
		return paletteContainer;
	}

	/**
	 * @generated
	 */
	private ToolEntry createFact1CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.Fact1CreationTool_title,
				Messages.Fact1CreationTool_desc,
				Collections.singletonList(RemoElementTypes.BooleanFact_2005));
		entry.setId("createFact1CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(RemoElementTypes
				.getImageDescriptor(RemoElementTypes.BooleanFact_2005));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createIMPLICATION1CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.IMPLICATION1CreationTool_title,
				Messages.IMPLICATION1CreationTool_desc,
				Collections.singletonList(RemoElementTypes.Implication_2007));
		entry.setId("createIMPLICATION1CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(RemoElementTypes
				.getImageDescriptor(RemoElementTypes.Implication_2007));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createAND2CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.AND2CreationTool_title,
				Messages.AND2CreationTool_desc,
				Collections.singletonList(RemoElementTypes.AndRule_2004));
		entry.setId("createAND2CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(RemoElementTypes
				.getImageDescriptor(RemoElementTypes.AndRule_2004));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createOR3CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(Messages.OR3CreationTool_title,
				Messages.OR3CreationTool_desc,
				Collections.singletonList(RemoElementTypes.OrRule_2006));
		entry.setId("createOR3CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(RemoElementTypes
				.getImageDescriptor(RemoElementTypes.OrRule_2006));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createPremise1CreationTool() {
		ArrayList<IElementType> types = new ArrayList<IElementType>(2);
		types.add(RemoElementTypes.LinksFromRules_4005);
		types.add(RemoElementTypes.LinksFromFacts_4006);
		LinkToolEntry entry = new LinkToolEntry(
				Messages.Premise1CreationTool_title,
				Messages.Premise1CreationTool_desc, types);
		entry.setId("createPremise1CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(RemoElementTypes
				.getImageDescriptor(RemoElementTypes.LinksFromRules_4005));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private static class NodeToolEntry extends ToolEntry {

		/**
		 * @generated
		 */
		private final List<IElementType> elementTypes;

		/**
		 * @generated
		 */
		private NodeToolEntry(String title, String description,
				List<IElementType> elementTypes) {
			super(title, description, null, null);
			this.elementTypes = elementTypes;
		}

		/**
		 * @generated
		 */
		public Tool createTool() {
			Tool tool = new UnspecifiedTypeCreationTool(elementTypes);
			tool.setProperties(getToolProperties());
			return tool;
		}
	}

	/**
	 * @generated
	 */
	private static class LinkToolEntry extends ToolEntry {

		/**
		 * @generated
		 */
		private final List<IElementType> relationshipTypes;

		/**
		 * @generated
		 */
		private LinkToolEntry(String title, String description,
				List<IElementType> relationshipTypes) {
			super(title, description, null, null);
			this.relationshipTypes = relationshipTypes;
		}

		/**
		 * @generated
		 */
		public Tool createTool() {
			Tool tool = new UnspecifiedTypeConnectionTool(relationshipTypes);
			tool.setProperties(getToolProperties());
			return tool;
		}
	}
}
